package com.mycompany.myapp.web.rest.electricbicyclecontroller;

import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.ElectricBicycle;
import com.mycompany.myapp.service.ElectricBicycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by wys on 2018/7/24
 */
@RestController
@RequestMapping("/api")
@Api(tags = "电动车管理员相关API")
public class ElecBicycleAdminController {

    @Autowired(required = true)
    ElectricBicycleService electricBicycleService;

    private final Logger log = LoggerFactory.getLogger(ElecBicycleAdminController.class);

    /**
     * 获的一辆可以使用的电动车
     * @return
     */
    @GetMapping("/getOneElectricBicycleUsed")
    @ApiOperation(value = "获的一辆可以使用的电动车",notes = "获的一辆可以使用的电动车")
    @ApiResponses(value = {
        @ApiResponse(code = 500,message = "获取异常")
    })
    @Timed
    public ResponseEntity<ElectricBicycle> getOneElectricBicycleUsed() {

        ElectricBicycle electricBicycle = electricBicycleService.getOneElectricBicycleUsed();

        return ResponseEntity.ok()
            .body(electricBicycle);
    }

    /**
     * 分发一辆需要维护的电动车分发给一名维护员
     * @param bicycleID
     * @param stewardID
     * @return
     */
    @PostMapping("/maintenanceBicycleToSteward")
    @ApiOperation(value = "分发一辆需要维护的电动车分发给一名维护员",notes = "分发一辆需要维护的电动车分发给一名维护员")
    @ApiResponses({
        @ApiResponse(code = 500,message = "异常")
    })
    @Timed
    public ResponseEntity<String> maintenanceBicycleToSteward(@RequestParam String bicycleID,@RequestParam String stewardID) {

        String result = "";

        result = electricBicycleService.maintenanceBicycleToSteward(bicycleID, stewardID);

        return ResponseEntity.ok()
            .body(result);
    }

    /**
     * 获得全部可以用的电动车
     * @return
     */
    @GetMapping("/getAllElectricBicycleUsed")
    @ApiOperation(value = "获得全部可以用的电动车",notes = "获得全部可以用的电动车")
    @Timed
    public List<ElectricBicycle> getAllElectricBicycleUsed() {

        return electricBicycleService.getAllElectricBicycleUsed();

    }

    /**
     * 获得全部需要维护的电动车
     * @return
     */
    @GetMapping("/getMaintenanceBicycle")
    @ApiOperation(value = "获得全部需要维护的电动车",notes = "获得全部需要维护的电动车")
    @Timed
    public List<ElectricBicycle> getMaintenanceBicycle() {

        return electricBicycleService.getMaintenanceBicycle();
    }

}
